package com.meijm;

import com.meijm.util.HTMLSpirit;
import lombok.Data;
import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.model.OOSpider;
import us.codecraft.webmagic.model.annotation.ExtractBy;
import us.codecraft.webmagic.model.annotation.HelpUrl;
import us.codecraft.webmagic.model.annotation.TargetUrl;
import us.codecraft.webmagic.pipeline.JsonFilePipeline;
import us.codecraft.webmagic.pipeline.PageModelPipeline;
import us.codecraft.webmagic.pipeline.Pipeline;

import javax.management.JMException;
import java.io.IOException;
import java.util.List;

@TargetUrl("https://bh.sb/post/\\d/")
@HelpUrl("https://bh.sb/post/category/main/page/\\d+/")
@Data
public class MyProcessor {

	@ExtractBy("//a[@id='cb_post_title_url']/text()")
	private String title;


	private List<String> imgTitle;

	private List<String> imgSrc;

	public String toString(){
		return  String.format("{title:%s,content:%s}",title, "aaa");
	}

	public static void main(String[] args) throws IOException, JMException {
		OOSpider.create(Site.me().setSleepTime(1000), MyProcessor.class).
				addUrl("http://www.cnblogs.com/scy251147").
				addPipeline(new Pipeline(){
					public void process(ResultItems resultItems, Task task) {
						System.out.println(resultItems.get("com.meijm.MyProcessor").toString());
					}
				}).thread(5).run();

	}

}
